package com.rzjm.api.netty.water.entity;

import cn.hutool.core.util.StrUtil;
import com.rzjm.api.netty.water.constant.ReceiveTypeEnum;
import com.rzjm.api.netty.water.constant.SendRtEnum;
import lombok.Data;


/**
 * @author WangWT
 * @Description: 向设备发送数据
 * @date 2023/2/24 16:24
 */
@Data
public class SendData {
    private Integer rt;
    private Long tag;
    private Integer v1;
    private Integer v2;
    private Integer v3;
    private Integer v4;
    private Integer v5;
    private Integer v6;
    private Integer v7;

    @Override
    public String toString() {
        String desc = getDesc();
        if (StrUtil.isBlank(desc)) {
            desc = "SendData{" +
                "rt=" + rt +
                ", tag=" + tag +
                ", v1=" + v1 +
                ", v2=" + v2 +
                ", v3=" + v3 +
                ", v4=" + v4 +
                ", v5=" + v5 +
                ", v6=" + v6 +
                ", v7=" + v7 +
                '}';
        }
        return desc;
    }

    private String getDesc() {
        try {
            if (rt == null) {
                return null;
            }
            SendRtEnum sendRtEnum = SendRtEnum.getByRt(rt);
            if (sendRtEnum == null) {
                return null;
            }
            String des = "";
            StringBuffer data = new StringBuffer();
            data.append(sendRtEnum.getDescription()).append(": {");
            switch (sendRtEnum) {
                case SEND_RT_0:
                    data.append("ID号:").append(v1);
                    break;
                case SEND_RT_1:
                    data.append("总通风时间:").append(v1)
                        .append(",第一次开启时间:").append(v2)
                        .append(",第二次开启时间:").append(v3)
                        .append(",开启后每次等待:").append(v4)
                        .append(",手动转自动时间:").append(v5);
                    break;
                case SEND_RT_2:
                    data.append("白天上传间隔时间:").append(v1)
                        .append(",起始时间:").append(v2)
                        .append(",停止时间:").append(v3)
                        .append(",晚上上传间隔时间:").append(v4)
                        .append(",起始时间:").append(v5)
                        .append(",停止时间:").append(v6);
                    break;
                case SEND_RT_3:
                    data.append("温度上限:").append(v1)
                        .append(",温度下限:").append(v2);
                    break;
                case SEND_RT_4:
                    data.append("最长时间设置:").append(v1);
                    break;
                case SEND_RT_5:
                    data.append("最长时间设置:").append(v1);
                    break;
                case SEND_RT_6:
                    data.append("区域选择:").append(v1)
                        .append(",开关指令:").append(getState(v2));
                    break;
                case SEND_RT_99:
                    data.append("心跳存在:").append(v1);
                    break;
                default:
                    break;

            }
            data.append("}");
            return data.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        int v1 = 99;
        StringBuffer data = new StringBuffer();
        data.append("控制模式:").append(v1 == 0 ? "自动" : (v1 == 1 ? "定时" : (v1 == 2 ? "手动" : "忽略")));
        data.append("控制模式:").append(v1 == 1 ? "定时" : (v1 == 2 ? "手动" : "忽略"));
        System.out.println(data);
    }

    private String getState(Integer state) {
        if (state == null) {
            return null;
        }
        switch (state) {
            case 0:
                return "关";
            case 1:
                return "开";
            case 2:
                return "开启中";
            case 3:
                return "关闭中";
            case 4:
                return "停止";
            case 5:
                return "开启暂停";
            case 6:
                return "关闭暂停";
            default:
                return String.valueOf(state);
        }
    }
}
